*******************************************************************************************
* Aarøe, Petersen & Arceneaux 2020

* replication dofile to produce Figures 1 and 2 in the main text and Figure A1-A3 in the online appendix. 
* This dofile also produces the reported results from the metaanalyses reported in the main text and in the online appendix

* The data in the datasets comes from the analyses in samples 1-7 described in the other dofiles for the paper
 
*******************************************************************************************

clear 
set more off

* the commands below generate the estimates for the meta-analyses reported in Figure 1, panels A-B in the main text
* The have been added manually to the dataset after running the code below

/*

import excel "Replication dataset for Figures 1-2 and A1-A2.xlsx", sheet("Sheet1") firstrow

rename sonscient_std conscient_std
rename Study study

* generating results for the meta analysis and entering them in the data set
bootstrap, cluster(study): metareg BIS_dydx if party_measure == 1 & study !=8 & copy !=1 & Analysisofrobustness ==., wsse(BIS_std) 
bootstrap, cluster(study): metareg BIS_dydx if party_measure == 2 & study !=8 & copy !=1 & Analysisofrobustness ==., wsse(BIS_std) 

* manually entering these two results from the meta -analyses into the excel datafile and saving it
clear */

import excel "Replication dataset for Figures 1-2 and A1-A2.xlsx", sheet("Sheet1") firstrow

* assigning labels to the dataset
rename sonscient_std conscient_std
rename Study study

label define BIS_mea 1 "Combined" 2 "Contamination" 3 "Pathogen" 4 "Germ" 5 "Meta"
label values BIS_mea BIS_mea

label define party_measure 1 "Party identification" 2 "Vote choice"
label values party_measure party_measure

recode study (8=0) (7=1) (6=2) (5=3) (4=4) (3=5) (2=6) (1=7)

label define study 7 "US 2012 presidential elect." 6 "US 2013 non-elect." /*
*/ 5 "US 2014 congressional elect." 4 "US 2015 non-elect." 3 "US 2016 non-elect." /*
*/ 2 "DK 2013 non-elect." 1 "DK 2016 non-elect." 0 "meta-analysis across samples", replace
label values study study


label define Analysisofrobustness 1 "only demographics as explanatory variables" /*
*/  2 "Big five and demographic as explanatory var" 3 "No Big five as control var"
label values Analysisofrobustness Analysisofrobustness

label define copy 1 "result direct copy of another result to ensure equal weight when multiple BIS measures in the same sample"
label values copy copy

*generate 90 per cent confidence intervals
* z-values for the calculation of the 90% confidence interval below were identified at http://sampson.byu.edu/courses/z2p2z-calculator.html
gen eL_BIS=BIS_dydx-(1.644852*BIS_std)
gen eU_BIS=BIS_dydx+(1.644852*BIS_std)

gen eL_Income=Income_dydx-(1.644852*Income_std)
gen eU_Income=Income_dydx+(1.644852*Income_std)

gen eL_Edu=edu_dydx-(1.644852*edu_std)
gen eU_Edu=edu_dydx+(1.644852*edu_std)

gen eL_Open=Open_dydx-(1.644852*openstd)
gen eU_Open=Open_dydx+(1.644852*openstd)

gen eL_Conscie=conscient_dydx-(1.644852*conscient_std)
gen eU_Conscie=conscient_dydx+(1.644852*conscient_std)

gen eL_Agree=agree_dydx-(1.644852*agree_std)
gen eU_Agree=agree_dydx+(1.644852*agree_std)

gen edu_dydx_num= edu_dydx*-1
gen Open_dydx_num = Open_dydx*-1
gen agree_dydx_num = agree_dydx *-1


save "Replication dataset for Figures 1-2 and A1-A2.dta", replace
* the stata version of the dataset for the meta-analysis and for Figures 1-2 and A1-3 is this file

********************************************************************************************
* Graphs for Figure 1, panel A, and Figure 2, panel A (i.e. effects on party identification)
*********************************************************************************************

use "Replication dataset for Figures 1-2 and A1-A2.dta", replace

* Figure 1, Panel A

* dropping all overservations that do not tap the effect on party identification 
* dropping all observations that represent analyses of robustness
sort study BIS_mea
keep if party_measure ==1 & copy !=1 & Analysisofrobustness ==.

* generating a variable to assign ID number to the observations
gen id = _n


bys id: ta BISLabel

* Format effect size for behavioral immune sensitivity to only display two decimals in the figure
format BIS_dydx %12.2f
 
*Figure 1, panel A:
scatter id BIS_dydx, msymbol(circle) ylabel(1 (1) 13, val angle(horizontal)) mlabel(BIS_dydx) mlabcolor(black)  /*
*/  mlabposition(12) mcolor(black) mlcolor(black) xline(0) legend(off) || rspike eL_BIS eU_BIS id   /*
*/ , hor mcolor(black) plotregion(fcolor(white)) graphregion(fcolor(white)) 
* using the graph editor in stata labels should be assigned manually to the figure based on Table A14
* OBS depending on the version used of stata and the type of lab top used the order of the coefficients in the graph main be re-arranged compared to the published article but the results are the same

clear

* generating numeric effect sizes for Figure 2, Panel A
use "Replication dataset for Figures 1-2 and A1-A2.dta", replace

bootstrap, cluster(study): metareg BIS_dydx if party_measure == 1 & study !=0 & copy !=1 & Analysisofrobustness ==., wsse(BIS_std) 
eststo BIS

bootstrap, cluster(study):  metareg edu_dydx_num if party_measure == 1 & study !=0 & copy !=1 & Analysisofrobustness ==. , wsse(edu_std)
eststo edu

bootstrap, cluster(study):  metareg Income_dydx if party_measure == 1 & study !=0 & copy !=1 & Analysisofrobustness ==. , wsse(Income_std)
eststo income

bootstrap, cluster(study):  metareg Open_dydx_num if party_measure == 1 & study !=0 & copy !=1 & Analysisofrobustness ==. , wsse(openstd)
eststo open

bootstrap, cluster(study):  metareg conscient_dydx if party_measure == 1 & study !=0 & copy !=1 & Analysisofrobustness ==. , wsse(conscient_std)
eststo conscient

bootstrap, cluster(study):  metareg agree_dydx_num if party_measure == 1 & study !=0 & copy !=1 & Analysisofrobustness ==. , wsse(agree_std)
eststo agree

coefplot BIS, bylabel("") || edu, bylabel("") || /*
*/ income, bylabel("") || open, bylabel("") || conscient, bylabel("") /*
*/ || agree, bylabel("") ||, keep(_cons) level (90) horizontal /*
*/  xlabel(0 (0.1) 0.40) xtitle("Average effect size across the tests", size(large)) /*
*/ mlabel format(%12.2f)  mlabposition(12) mcolor(black) legend(off) byopts(cols(1)) /*
*/ plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s2mono)
* using the graph editor function in stata labels should susequently be assigned to the graph
clear

*********************************************************************************************
* Graphs for Figure 1, panel B, and Figure 2, panel B (i.e. effects on vote choice)
*********************************************************************************************

* Figure 1, Panel B
use "Replication dataset for Figures 1-2 and A1-A2.dta", replace

* dropping all overservations that do not tap the effect on vote choice and all observations that represent analyses of robustness
sort study BIS_mea
keep if party_measure ==2 & copy !=1 & Analysisofrobustness ==.

* generating a variable to assign ID number to the observations
gen id = _n
bys id: ta study

* correcting a labelling mistake (the correct label is "US 2014: Pathogen" if BIS_dydx = .1062172
replace BISLabel = "US 2014: Pathogen" in 9

format BIS_dydx %12.2f

scatter id BIS_dydx, msymbol(circle) ylabel(1 (1) 12, val angle(horizontal)) mlabel(BIS_dydx) mlabcolor(black)  /*
*/  mlabposition(12) mcolor(black) mlcolor(black) xline(0) legend(off) || rspike eL_BIS eU_BIS id   /*
*/ , hor mcolor(black) plotregion(fcolor(white)) graphregion(fcolor(white)) 
* using the graph editor in Stata labels were assigned manually to the figure based on Table A15
* OBS depending on the version used of stata and the type of lab top used the order of the coefficients in the graph main be re-arranged compared to the published article but the results are the same

clear

* generating numeric effect sizes for Figure 2, Panel B
use "Replication dataset for Figures 1-2 and A1-A2.dta", replace
drop if study ==0

bootstrap, cluster(study): metareg BIS_dydx if party_measure == 2 & study !=0 & copy !=1 & Analysisofrobustness ==., wsse(BIS_std) 
eststo BIS

bootstrap, cluster(study): metareg edu_dydx_num if party_measure == 2 & study !=0  & copy !=1 & Analysisofrobustness ==., wsse(edu_std)
eststo edu

bootstrap, cluster(study): metareg Income_dydx if party_measure == 2 & study !=0  & copy !=1 & Analysisofrobustness ==., wsse(Income_std)
eststo income

bootstrap, cluster(study): metareg Open_dydx_num if party_measure == 2 & study !=0  & copy !=1 & Analysisofrobustness ==., wsse(openstd)
eststo open

bootstrap, cluster(study): metareg conscient_dydx if party_measure == 2 & study !=0 & copy !=1 & Analysisofrobustness ==., wsse(conscient_std)
eststo conscient

bootstrap, cluster(study): metareg agree_dydx_num if party_measure == 2 & study !=0  & copy !=1 & Analysisofrobustness ==., wsse(agree_std)
eststo agree

coefplot BIS, bylabel("") || edu, bylabel("") || /*
*/ income, bylabel("") || open, bylabel("") || conscient, bylabel("") /*
*/ || agree, bylabel("") ||, keep(_cons) level (90) horizontal /*
*/  xlabel(0 (0.1) 0.40) xtitle("Average effect size across the tests", size(large)) /*
*/ mlabel format(%12.2f)  mlabposition(12) mcolor(black) legend(off) byopts(cols(1)) /*
*/ plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s2mono)
* using the graph editor function in stata we subsequently manually assign labels to the graph

clear



******************************************************************************************************
* analyses of robustness for Figure 2 reported in Online Appendix A3.2, Figures A1-A2
*******************************************************************************************************
 
import excel "Replication dataset for Figures 1-2 and A1-A2.xlsx", sheet("Sheet1") firstrow

******************************************************************************
* recodings
******************************************************************************

rename sonscient_std conscient_std
rename Study study

label define BIS_mea 1 "Combined" 2 "Contamination" 3 "Pathogen" 4 "Germ" 5 "Meta"
label values BIS_mea BIS_mea

label define party_measure 1 "Party identification" 2 "Vote choice"
label values party_measure party_measure

label define Analysisofrobustness 1 "only demographics as explanatory variables" /*
*/  2 "Big five and demographic as explanatory var" 3 "No Big five as control var"
label values Analysisofrobustness Analysisofrobustness

label define copy 1 "result direct copy of another result to ensure equal weight when multiple BIS measures in the same sample"
label values copy copy

gen edu_dydx_num= edu_dydx*-1
gen Open_dydx_num = Open_dydx*-1
gen agree_dydx_num = agree_dydx *-1

*generate 90 per cent confidence intervals
* z-values identified at http://sampson.byu.edu/courses/z2p2z-calculator.html
gen eL_BIS=BIS_dydx-(1.644852*BIS_std)
gen eU_BIS=BIS_dydx+(1.644852*BIS_std)

gen eL_Income=Income_dydx-(1.644852*Income_std)
gen eU_Income=Income_dydx+(1.644852*Income_std)

gen eL_Edu=edu_dydx-(1.644852*edu_std)
gen eU_Edu=edu_dydx+(1.644852*edu_std)

gen eL_Open=Open_dydx-(1.644852*openstd)
gen eU_Open=Open_dydx+(1.644852*openstd)

gen eL_Conscie=conscient_dydx-(1.644852*conscient_std)
gen eU_Conscie=conscient_dydx+(1.644852*conscient_std)

gen eL_Agree=agree_dydx-(1.644852*agree_std)
gen eU_Agree=agree_dydx+(1.644852*agree_std)

******************************************************************************

/* Figure 1A, panel A: Average effect sizes for education and income across the tests estimated without pathogen avoidance 
motivation and big five personality traits in the model (panel A: party identification) */

eststo clear
bootstrap, cluster(study): metareg BIS_dydx if party_measure == 1 & study !=8 & study !=0 & Analysisofrobustness !=3, wsse(BIS_std)
eststo BIS

bootstrap, cluster(study): metareg edu_dydx_num if party_measure == 1 & study !=8 & study !=0 & Analysisofrobustness==1 , wsse(edu_std)
eststo edu

bootstrap, cluster(study): metareg Income_dydx if party_measure == 1 & study !=8 & study !=0 & Analysisofrobustness==1, wsse(Income_std)
eststo income

/* Figure A1, panel A: Average effect sizes for education and income across the tests estimated without pathogen avoidance 
motivation and big five personality traits in the model (panel A: party identification) */

* NB Edit figure - font size medium large, ylabels + mlabels large
coefplot BIS, bylabel("") || edu, bylabel("") || /*
*/ income, bylabel("") ||, keep(_cons) level (90) horizontal /*
*/  xlabel(0 (0.1) 0.30) xtitle("Average effect size across the tests", size(medlarge)) /*
*/ mlabel format(%12.2f) msize(medlarge) mlabposition(12) mcolor(black) legend(off) byopts(cols(1)) /*
*/ plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s2mono)

eststo clear

/* Figure A1, panel B: Average effect sizes for education and income across the tests estimated without pathogen avoidance 
motivation and big five personality traits in the model (panel B: vote choice) */
bootstrap, cluster(study): metareg BIS_dydx if party_measure == 2 & study !=8 & study !=0 & Analysisofrobustness !=3, wsse(BIS_std)
eststo BIS

bootstrap, cluster(study): metareg edu_dydx_num if party_measure == 2 & study !=8 & study !=0 & Analysisofrobustness==1 , wsse(edu_std)
eststo edu

bootstrap, cluster(study): metareg Income_dydx if party_measure == 2 & study !=8 & study !=0 & Analysisofrobustness==1, wsse(Income_std)
eststo income

coefplot BIS, bylabel("") || edu, bylabel("") || /*
*/ income, bylabel("") ||, keep(_cons) level (90) horizontal /*
*/  xlabel(0 (0.1) 0.30) xtitle("Average effect size across the tests", size(medlarge)) /*
*/ mlabel format(%12.2f) msize(medlarge) mlabposition(12) mcolor(black) legend(off) byopts(cols(1)) /*
*/ plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s2mono)


/* Figure A2 Average effect sizes for pathogen avoidance motivation estimated without the big five personality traits in the model
Panel A: party identification */

gen include =.
replace include =1 if Analysisofrobustness ==3
replace include =1 if study ==1
replace include =1 if study ==6

bootstrap, cluster(study): metareg BIS_dydx if party_measure == 1 & study !=8 & study !=0 & include ==1, wsse(BIS_std)
eststo BIS

coefplot BIS, bylabel("") ||, keep(_cons) level (90) horizontal /*
*/  xlabel(0 (0.1) 0.40) xtitle("Average effect size across the tests", size(medlarge)) /*
*/ mlabel format(%12.2f) msize(medlarge) mlabposition(12) mcolor(black) legend(off) byopts(cols(1)) /*
*/ plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s2mono)


/* Figure A2 Average effect sizes for pathogen avoidance motivation estimated without the big five personality traits in the model
Panel B: vote choice */
bootstrap, cluster(study): metareg BIS_dydx if party_measure == 2 & study !=8 & study !=0 & include ==1, wsse(BIS_std)
eststo BIS

coefplot BIS, bylabel("") ||, keep(_cons) level (90) horizontal /*
*/  xlabel(0 (0.1) 0.40) xtitle("Average effect size across the tests", size(medlarge)) /*
*/ mlabel format(%12.2f) msize(medlarge) mlabposition(12) mcolor(black) legend(off) byopts(cols(1)) /*
*/ plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s2mono)

*******************************************************************************
* Analyses for Figure A3 in the Online Appendix
*******************************************************************************

clear
import excel "Replication dataset for Figures 1-2 and A1-A2.xlsx", sheet("Sheet1") firstrow

label define Ideotype 1 "ideo on social issues" 2 "ideo on economic issues" 3 "lib-con continuum"
label values Ideotype Ideotype

label define Ideomeasure 1 "T & H scales" 2 "Danish NES scales" 3 "lib-con continuum" 4 "Wilson-Patterson" 
label values Ideomeasure Ideomeasure

label define BISmea 1 "Combined measure" 2 "Contamination" 3 "Pathogen" 4 "Germ aversion"
label values BISmea BISmea

sort Ideotype BISmea

format Ideo %12.2f 

*generating estimates for the meta-analyses 
* the estimates from the meta-analyses have been manually added to the dataset based on the code below

* the results from the command below have been entered into excell
/* bootstrap, cluster(Sample): metareg Ideo if Ideotype == 1, wsse(SD) level(90)
est store m1
bootstrap, cluster(Sample): metareg Ideo if Ideotype == 2, wsse(SD) level(90)
est store m2
bootstrap, cluster(Sample): metareg Ideo if Ideotype == 3, wsse(SD) level(90)
est store m3
bootstrap, cluster(Sample): metareg Ideo if Ideotype == 4, wsse(SD) level(90)
est store m4 */


gen eL_Ideo=Ideo-(1.644852*SD)
gen eU_Ideo=Ideo+(1.644852*SD)

recode Sample (8=0) (7=1) (6=2) (5=3) (4=4) (3=5) (2=6) (1=7)
label define Sample 7 "US 2012 presidential elect." 6 "US 2013 non-elect." /*
*/ 5 "US 2014 congressional elect." 4 "US 2015 non-elect." 3 "US 2016 non-elect." /*
*/ 2 "DK 2013 non-elect." 1 "DK 2016 non-elect." 0 "meta-analysis across samples", replace
label values Sample Sample

save "Replication dataset for Figure A3 (with main meta-analyses coefficients).dta", replace


******************************************************************************************
* Figure A3, Panel A Social issues
******************************************************************************************
keep if Ideotype !=3
drop if Ideotype ==.
gen id_social = _n if Ideotype ==1
recode id_social (9=5)
bys id_id_social: ta BISmea Ideomeasure


scatter id_social Ideo if Ideotype ==1, msymbol(circle) ylabel(1 (1) 5, val angle(horizontal)) mlabel(Ideo) mlabcolor(black)  /*
*/  mlabposition(12) mcolor(black) mlcolor(black) xline(0) legend(off) || rspike eL_Ideo eU_Ideo id_social if Ideotype ==1   /*
*/ , hor mcolor(black) plotregion(fcolor(white)) graphregion(fcolor(white)) 
* using the graph editor in stata labels should be manually assigned to the graph
* OBS depending on the version used of stata and the type of lab top used the order of the coefficients in the graph main be re-arranged compared to the published article but the results are the same

******************************************************************************************
* Figure A3, Panel B Economic issues
******************************************************************************************

gen id_econ = _n if Ideotype ==2
bys id_econ: ta BISmea Ideomeasure
recode id_econ (6=1) (7=2) (8=3) (9=4) (10=5)

scatter id_econ Ideo if Ideotype ==2, msymbol(circle) ylabel(1 (1) 5, val angle(horizontal)) mlabel(Ideo) mlabcolor(black)  /*
*/  mlabposition(12) mcolor(black) mlcolor(black) xline(0) legend(off) || rspike eL_Ideo eU_Ideo id_econ if Ideotype ==2   /*
*/ , hor mcolor(black) plotregion(fcolor(white)) graphregion(fcolor(white))
* using the graph editor in stata labels should be manually assigned to the graph
* OBS depending on the version used of stata and the type of lab top used the order of the coefficients in the graph main be re-arranged compared to the published article but the results are the same


***************************************************************************
* Figure A3, Panel C Wilson-Patterson
***************************************************************************
clear

use "Replication data for Figure A3 (with meta-analysis coefficients).dta", replace

keep if Ideotype ==4
gen id_WP = _n if Ideotype ==4
recode id_WP (9=5)

scatter id_WP Ideo if Ideotype ==4, msymbol(circle) ylabel(1 (1) 3, val angle(horizontal)) mlabel(Ideo) mlabcolor(black)  /*
*/  mlabposition(12) mcolor(black) mlcolor(black) xline(0) legend(off) || rspike eL_Ideo eU_Ideo id_WP if Ideotype ==4   /*
*/ , hor mcolor(black) plotregion(fcolor(white)) graphregion(fcolor(white)) 
* using the graph editor in stata labels should be manually assigned to the graph
* OBS depending on the version used of stata and the type of lab top used the order of the coefficients in the graph main be re-arranged compared to the published article but the results are the same


***************************************************************************
* Figure A3, Panel D. Ideological self-placement on the liberal-conservative continuum
***************************************************************************
clear
import excel "Replication data for Figure A3 (with meta-analysis coefficients).xlsx", sheet("Sheet1") firstrow

label define Ideotype 1 "ideo on social issues" 2 "ideo on economic issues" 3 "lib-con continuum"
label values Ideotype Ideotype

label define Ideomeasure 1 "T & H scales" 2 "Danish NES scales" 3 "lib-con continuum" 4 "Wilson-Patterson" 
label values Ideomeasure Ideomeasure

label define BISmea 1 "Combined measure" 2 "Contamination" 3 "Pathogen" 4 "Germ aversion"
label values BISmea BISmea

sort Ideotype BISmea

format Ideo %12.2f 


label define Sample 7 "US 2012 presidential elect." 6 "US 2013 non-elect." /*
*/ 5 "US 2014 congressional elect." 4 "US 2015 non-elect." 3 "US 2016 non-elect." /*
*/ 2 "DK 2013 non-elect." 1 "DK 2016 non-elect." 0 "meta-analysis across samples", replace
label values Sample Sample

gen samples457 = Sample
recode samples457 (4=1) (3=1) (1=1) 

bootstrap, cluster(Sample): metareg Ideo if samples457 == 1, wsse(SD) level(90)
est store m3
* We manually type insto stata the results of this latter meta analysis b = .1142484, SD = .0281872, N = 3 
*This coefficient is not added in the current dataset

sort Ideotype BISmea

keep if Ideotype ==3
gen id_gen = _n if Ideotype ==3
ta id_gen


gen eL_Ideo=Ideo-(1.644852*SD)
gen eU_Ideo=Ideo+(1.644852*SD)

format Ideo %12.2f

scatter id_gen Ideo if Ideotype ==3, msymbol(circle) ylabel(1 (1) 15, val angle(horizontal)) mlabel(Ideo) mlabcolor(black)  /*
*/  mlabposition(12) mcolor(black) mlcolor(black) xline(0) legend(off) || rspike eL_Ideo eU_Ideo id_gen if Ideotype ==3   /*
*/ , hor mcolor(black) plotregion(fcolor(white)) graphregion(fcolor(white))
* using the graph editor in stata labels should be manually assigned to the graph
* OBS depending on the version used of stata and the type of lab top used the order of the coefficients in the graph main be re-arranged compared to the published article but the results are the same

